package com.CGFrame.struts.action.categorySet;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.CGFrame.struts.POJOs.Category;
import com.CGFrame.struts.POJOs.Company;
import com.CGFrame.struts.bean.ProjectOperate;
import com.CGFrame.struts.bean.ProjectOperateFactory;
import com.CGFrame.struts.bean.category.CategoryBean;
import com.CGFrame.struts.bean.log.LogHistoryBean;

public class DelAction extends Action {

	@Override
	public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
		CategoryBean cb = new CategoryBean();
		String categoryId = request.getParameter("categoryId");
		cb.delCategory(Integer.valueOf(categoryId));
		
		HttpSession session = request.getSession();
		ProjectOperateFactory.closeprojectOperate();
		String companyId = (String)session.getAttribute("CompanyID");
		ProjectOperate pop=ProjectOperateFactory.getprojectOperate();
		Company c = (Company)pop.UniqueQuery("Company", "companyId,"+companyId);
		request.setAttribute( "categories", c.getCategories() );
		
		LogHistoryBean logBean = new LogHistoryBean();
		String regUserId = (String)request.getSession().getAttribute("RegUserID");
		logBean.saveByReguserId(regUserId, LogHistoryBean.DELETE,null, "Category",Integer.valueOf(categoryId) );
		
		return mapping.findForward("queryCategory");
	}
	
}
